package api

import (
	"api_gateway/basic/config"
	__ "api_gateway/basic/proto"
	"api_gateway/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func AddDriver(c *gin.Context) {
	var req request.AddDriver
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "验证失败",
			"data":    err.Error(),
		})
		return
	}
	dirvers, err := config.UserClient.AddDirvers(c, &__.AddDirversReq{
		UserId:           int64(req.UserId),
		DriverLicenseUrl: req.DriverLicenseUrl,
		LicenseNumber:    int64(req.LicenseNumber),
		CarType:          req.CarType,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "上传失败",
			"data":    err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "上传成功",
		"data":    dirvers,
	})
}

func CheckDirverStatus(c *gin.Context) {
	var req request.CheckDirverStatus
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "验证失败",
			"data":    err.Error(),
		})
		return
	}
	status, err := config.UserClient.CheckDirverStatus(c, &__.CheckDirverStatusReq{
		UserId: int64(req.Id),
		Status: int64(req.Status),
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "审核失败",
			"data":    err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "审核成功",
		"data":    status,
	})
}
